// AnyChat for Web SDK

/********************************************
 *				�¼��ص�����				*
 *******************************************/

// �첽��Ϣ֪ͨ���������ӷ���������¼ϵͳ�����뷿�����Ϣ
function OnAnyChatNotifyMessage(dwNotifyMsg, wParam, lParam) {
	switch (dwNotifyMsg) {
		case WM_GV_CONNECT: OnAnyChatConnect(wParam, lParam); break;
		case WM_GV_LOGINSYSTEM: OnAnyChatLoginSystem(wParam, lParam); break;
		case WM_GV_ENTERROOM: OnAnyChatEnterRoom(wParam, lParam); break;
		case WM_GV_ONLINEUSER: OnAnyChatRoomOnlineUser(wParam, lParam); break;
		case WM_GV_USERATROOM: OnAnyChatUserAtRoom(wParam, lParam); break;
		case WM_GV_LINKCLOSE: OnAnyChatLinkClose(wParam, lParam); break;
		case WM_GV_MICSTATECHANGE: OnAnyChatMicStateChange(wParam, lParam); break;
		case WM_GV_CAMERASTATE: OnAnyChatCameraStateChange(wParam, lParam); break;
		case WM_GV_P2PCONNECTSTATE: OnAnyChatP2PConnectState(wParam, lParam); break;
		case WM_GV_PRIVATEREQUEST: OnAnyChatPrivateRequest(wParam, lParam); console.log(wParam, lParam); break;
		case WM_GV_PRIVATEECHO: OnAnyChatPrivateEcho(wParam, lParam); break;
		case WM_GV_PRIVATEEXIT: OnAnyChatPrivateExit(wParam, lParam); break;
		case WM_GV_USERINFOUPDATE: OnAnyChatUserInfoUpdate(wParam, lParam); break;
		case WM_GV_FRIENDSTATUS: OnAnyChatFriendStatus(wParam, lParam); break;
		default:
			break;
	}
}

// �յ�������Ϣ
function OnAnyChatTextMessage(dwFromUserId, dwToUserId, bSecret, lpMsgBuf, dwLen) {
	DisplayTextMessage(dwFromUserId, lpMsgBuf);
	console.log(dwFromUserId, lpMsgBuf);
}

// �յ�͸��ͨ����������
function OnAnyChatTransBuffer(dwUserId, lpBuf, dwLen) {
	console.log("触发监控回调。接收到OnAnyChatTransBuffer信息");
	alert("�յ�:" + dwUserId + "�û����͹�����͸��ͨ���������ݣ�" + lpBuf);
	console.log("�յ�:" + dwUserId + "�û����͹�����͸��ͨ���������ݣ�" + lpBuf);
	console.log("�յ����ȣ�" + lpBuf.length);
}

// �յ�͸��ͨ������չ����������
function OnAnyChatTransBufferEx(dwUserId, lpBuf, dwLen, wParam, lParam, dwTaskId) {
	alert("�յ�:" + dwUserId + "�û����͹�������չ͸��ͨ���������ݣ�" + lpBuf);
	console.log("�յ�:" + dwUserId + "�û����͹�������չ͸��ͨ���������ݣ�" + lpBuf);
	console.log("�յ����ȣ�" + lpBuf.length);
}

// �ļ��������֪ͨ
function OnAnyChatTransFile(dwUserId, lpFileName, lpTempFilePath, dwFileLength, wParam, lParam, dwTaskId) {

	//alert("�յ��ļ�:"+dwUserId+"�û����͹������ļ���"+"����·���ڣ�"+lpTempFilePath);
	console.log("�յ��ļ�:" + dwUserId + "�û����͹������ļ���" + "����·���ڣ�" + lpTempFilePath);
}

// ϵͳ�����ı�֪ͨ
function OnAnyChatVolumeChange(device, dwCurrentVolume) {

}

// �յ����������͵�SDK Filter����
function OnAnyChatSDKFilterData(lpBuf, dwLen) {
	console.log(lpBuf, dwLen);
}

// �յ�¼�����������¼�
function OnAnyChatRecordSnapShot(dwUserId, lpFileName, dwParam, bRecordType) {
	//console.log(bRecordType)
	//console.log("1111")

	if (bRecordType == 0) {
		//alert("ץ�ĳɹ����ļ�·���ǣ�"+lpFileName);
		//console.log("ץ�ĳɹ����ļ�·���ǣ�"+lpFileName);
	}
	else if (bRecordType == 1) {
		//alert("¼��ɹ����ļ�·���ǣ�"+lpFileName);
		//console.log("¼��ɹ����ļ�·���ǣ�"+lpFileName);
	}
}
function OnAnyChatRecordSnapShotEx(dwUserId, lpFileName, dwElapse, dwFlags, dwParam, lpUserStr) {
	//AddLog('OnAnyChatRecordSnapShotEx(' + dwUserId + ',' + lpFileName + ',' + dwElapse + ',' + dwFlags + ',' + dwParam + ',' + lpUserStr + ')', LOG_TYPE_EVENT);
	//AddLog("¼��/���ճɹ����ļ�·��Ϊ��" + lpFileName , LOG_TYPE_NORMAL);
	DisplayTextMessage(-1, lpFileName);

	var VADCtrol = 1;
	BRAC_SetSDKOption(BRAC_SO_AUDIO_VADCTRL, VADCtrol);

	var html = "�ļ�·��Ϊ��" + lpFileName;
	$("#dialog-confirm").html(html);
	$("#dialog-confirm").dialog({
		modal: true,
		width: 600,
		buttons: {
			"ȷ��": function () {
				$(this).dialog("close");
				$("#dialog-confirm").html("");
			}
		}
	});

	$("#dialog-confirm").parent().append("<iframe frameborder=0 scrolling=no style=\"background-color:transparent; position: absolute; z-index: -1; width: 100%; height: 100%; top: 0;left:0;\"></iframe>");

	//$.messager.alert("��ʾ","�ļ�·��Ϊ��" + lpFileName);
	//$("#serviceInfoTable tr:eq(5) td:eq(0)").text("�ļ�·��Ϊ��" + lpFileName);
}

// �յ�¼�����������¼�����չ2������errorcode��
function OnAnyChatRecordSnapShotEx2(dwUserId, dwErrorCode, lpFileName, dwElapse, dwFlags, dwParam, lpUserStr) {
	if (dwErrorCode !== 0) {
		DisplayTextMessage(-1, "¼���쳣�������룺" + dwErrorCode);
	}
}

// AnyChatCoreSDK�첽�¼�
function OnAnyChatCoreSDKEvent(dwEventType, lpEventJsonStr) {
	//console.log("�첽֪ͨ��" +"Type:" +dwEventType+":"+lpEventJsonStr);
	//DisplayTextMessage(-1, "�첽֪ͨ��" +"Type:" +dwEventType+":"+lpEventJsonStr);
	//	var myDate1 = new Date();

	//	console.log(myDate1+"AnyChatCoreSDK�첽�¼�:");

	//console.log("�¼����ͣ�"+dwEventType+"��\n�¼�����:"+lpEventJsonStr);

	/*if(dwEventType == 2){
		
		console.log("���ӱ����¼�֪ͨ");
		var myDate = new Date();
		//��ȡ������ʱ��
		//console.log("Time:"+myDate.toLocaleString());
	
		//console.log("OnAnyChatCoreSDKEvent{")
		//console.log("dwEventType:"+dwEventType);
		//console.log("lpEventJsonStr:"+lpEventJsonStr);
		//console.log("}");
		
		//console.log("Time:"+myDate.toLocaleString()+" ,length:"+lpEventJsonStr.length);
	}*/
	//
	if (dwEventType == 4) {
		//AddLog("�첽֪ͨ��" +"Type:" +dwEventType+":"+lpEventJsonStr, LOG_TYPE_EVENT);
		console.log("¼��״̬�¼���" + "Type:" + dwEventType + ":" + lpEventJsonStr);
	}

	if (dwEventType == 13) {
		//AddLog("�첽֪ͨ��" +"Type:" +dwEventType+":"+lpEventJsonStr, LOG_TYPE_EVENT);
		console.log("¼��״̬�¼���" + "Type:" + dwEventType + ":" + lpEventJsonStr);
	}

	if (dwEventType === 100) {

		console.log("ҵ�񻺳�������-�첽�ص��¼�֪ͨ");
		var myDate = new Date();
		//��ȡ������ʱ��
		//console.log("Time:"+myDate.toLocaleString());

		//console.log("OnAnyChatCoreSDKEvent{")
		//console.log("dwEventType:"+dwEventType);
		//console.log("lpEventJsonStr:"+lpEventJsonStr);
		//console.log("}");

		//console.log("Time:"+myDate.toLocaleString()+" ,length:"+lpEventJsonStr.length);
	}
	//
	if (dwEventType === 104) {

		console.log("�����û��Զ������������-�첽�ص��¼�֪ͨ");
		var myDate = new Date();
		//��ȡ������ʱ��
		//console.log("Time:"+myDate.toLocaleString());

		console.log("OnAnyChatCoreSDKEvent{")
		console.log("dwEventType:" + dwEventType);
		console.log("lpEventJsonStr:" + lpEventJsonStr);
		console.log("}");

		console.log("Time:" + myDate.toLocaleString() + " ,length:" + lpEventJsonStr.length);
	}

}



/********************************************
 *		AnyChat SDK����ҵ������				*
 *******************************************/

// �ͻ������ӷ�������bSuccess��ʾ�Ƿ����ӳɹ���errorcode��ʾ��������
function OnAnyChatConnect(bSuccess, errorcode) {
	AddLog("OnAnyChatConnect(errorcode=" + errorcode + ")", LOG_TYPE_EVENT);
	if (errorcode == 0) {

	}
	else {
		DisplayLoadingDiv(false);
	}
}

// �ͻ��˵�¼ϵͳ��dwUserId��ʾ�Լ����û�ID�ţ�errorcode��ʾ��¼�����0 �ɹ�������Ϊ�������룬�ο��������붨��
function OnAnyChatLoginSystem(dwUserId, errorcode) {
	DisplayLoadingDiv(false);
	AddLog("OnAnyChatLoginSystem(userid=" + dwUserId + ", errorcode=" + errorcode + ")", LOG_TYPE_EVENT);
	if (errorcode == 0) {
		mSelfUserId = dwUserId;
		ShowHallDiv(true);
	} else {
		ShowHallDiv(false);
	}

}

// �ͻ��˽��뷿�䣬dwRoomId��ʾ�����뷿���ID�ţ�errorcode��ʾ�Ƿ���뷿�䣺0�ɹ����룬����Ϊ��������
function OnAnyChatEnterRoom(dwRoomId, errorcode) {
	DisplayLoadingDiv(false);
	AddLog("OnAnyChatEnterRoom(roomid=" + dwRoomId + ", errorcode=" + errorcode + ")", LOG_TYPE_EVENT);
	if (errorcode == 0) {
		ShowRoomDiv(true);

		var BRAC_SO_LOCALVIDEO_WATERMARK = 113;   ///< ��Ƶ����ˮӡ���ƣ�ͼƬ�����֣�
		var jsonmark = {
			"textoverlay": {
				"fontcolor": "0xffffff",
				"alpha": 100,
				"posx": 5,
				"posy": 5,
				"fontsize": 15,
				"useservertime": 1,
				"text": "test [timestamp] ʵʱˮӡ"
			},
			"watermark": {
				"alpha": 10,
				"posx": 10,
				"posy": 10,
				"overlayimgwidth": 32,
				"overlayimgheight": 32,
				"imagepath": "D:\\Ԫ����ֽ����\\img\\4add7f57b8013fdda379730a45d9d38a.jpg"
			}
		};
		var jsonMARK = JSON.stringify(jsonmark);
		var errorcode = BRAC_SetUserStreamInfo(-1, 0, BRAC_SO_LOCALVIDEO_WATERMARK, jsonMARK);
		//var errorcode = BRAC_SetSDKOption(BRAC_SO_LOCALVIDEO_WATERMARK,jsonMARK);



		console.log("����ˮӡ");


		RoomUserListControl(mSelfUserId, true);		// ���Լ������û��б�
		BRAC_UserCameraControl(mSelfUserId, 1); 	// �򿪱�����Ƶ
		BRAC_UserSpeakControl(mSelfUserId, 1); 		// �򿪱�������

		meiyan_level();

		ShowNotifyMessage("Welcome use AnyChat, successfully enter the room:" + dwRoomId, NOTIFY_TYPE_SYSTEM);
		// ���ñ�����Ƶ��ʾλ��
		BRAC_SetVideoPos(mSelfUserId, GetID("AnyChatLocalVideoDiv"), "ANYCHAT_VIDEO_LOCAL");
		//BRAC_SetVideoPos(mSelfUserId, GetID("AnyChatRemoteVideoDiv"), "ANYCHAT_VIDEO_REMOTE");
		//BRAC_SetVideoPos(0, GetID("AnyChatLocalVideoDiv"), "ANYCHAT_VIDEO_LOCAL");
		// ����Զ����Ƶ��ʾλ�ã�û�й������û���ֻ��ռλ�ã�
		BRAC_SetVideoPos(0, GetID("AnyChatRemoteVideoDiv"), "ANYCHAT_VIDEO_REMOTE");
		//BRAC_SetVideoPos(mSelfUserId, GetID("AnyChatRemoteVideoDiv"), "ANYCHAT_VIDEO_REMOTE");

		//mRefreshVolumeTimer = setInterval(function () {
		//GetID("LocalAudioVolume").style.width = GetID("AnyChatLocalVideoDiv").offsetHeight * BRAC_QueryUserStateInt(mSelfUserId, BRAC_USERSTATE_SPEAKVOLUME) / 100 + "px";
		//	if(mTargetUserId != -1)
		//GetID("RemoteAudioVolume").style.width = GetID("AnyChatRemoteVideoDiv").offsetHeight * BRAC_QueryUserStateInt(mTargetUserId, BRAC_USERSTATE_SPEAKVOLUME) / 100 + "px";
		//	else
		//		GetID("RemoteAudioVolume").style.width = "0px";
		// }, 100);
		var mRefreshBrateTimer = setInterval(function () {

			//GetID("div_localstreamname"+k).innerHTML = k+"·��Ƶ���ʣ�"+parseInt(BRAC_GetUserStreamInfoInt(-1,k,BRAC_STREAMINFO_VIDEOBITRATE)/1000)+"KBps";//��Ƶ���ʡ���Ƶ���� +"��\n"+k+"·��Ƶ���ʣ�"+parseInt(BRAC_GetUserStreamInfoInt(-1,k,BRAC_STREAMINFO_AUDIOBITRATE)/1000)+"Kbps"

			//console.log("�û�:"+mTargetUserId+"-��Ƶ���ʣ�"+BRAC_QueryUserStateInt(mTargetUserId,10)/1000+"Kbps");
			//console.log("����:-1"+"-��Ƶ���ʣ�"+BRAC_QueryUserStateInt(-1,10)/1000+"Kbps");


			//console.log("�û�:"+mTargetUserId+"-��Ƶ���ʣ�"+BRAC_GetUserStreamInfoInt(mTargetUserId, 0, BRAC_STREAMINFO_AUDIOBITRATE)/1000+"Kbps");
			//console.log("����:-1"+"-��Ƶ���ʣ�"+BRAC_GetUserStreamInfoInt(-1, 0, BRAC_STREAMINFO_AUDIOBITRATE)/1000+"Kbps");

		}, 1000);

	} else {

	}


	//var tag=BRAC_RECORD_FLAGS_VIDEO+BRAC_RECORD_FLAGS_AUDIO+BRAC_RECORD_FLAGS_MIXVIDEO+BRAC_RECORD_FLAGS_MIXAUDIO+BRAC_RECORD_FLAGS_STEREO;
	//setTimeout(BRAC_StreamRecordCtrl(-1,1,tag,0), 5000);
}

// �յ���ǰ����������û���Ϣ�����뷿��󴥷�һ�Σ�dwUserCount��ʾ�����û����������Լ�����dwRoomId��ʾ����ID
function OnAnyChatRoomOnlineUser(dwUserCount, dwRoomId) {
	AddLog("OnAnyChatRoomOnlineUser(count=" + dwUserCount + ", roomid=" + dwRoomId + ")", LOG_TYPE_EVENT);
	var useridlist = BRAC_GetOnlineUser();
	for (var i = 0; i < useridlist.length; i++) {
		RoomUserListControl(useridlist[i], true);
	}
	// ��������һ���û�������Ƶ
	for (var k = 0; k < useridlist.length; k++) {
		if (useridlist[k] == mSelfUserId)
			continue;
		RequestOtherUserVideo(useridlist[k]);
		break;
	}
}

// �û����루�뿪�����䣬dwUserId��ʾ�û�ID�ţ�bEnterRoom��ʾ���û��ǽ��루1�����뿪��0������
function OnAnyChatUserAtRoom(dwUserId, bEnterRoom) {
	AddLog("OnAnyChatUserAtRoom(userid=" + dwUserId + ", benter=" + bEnterRoom + ")", LOG_TYPE_EVENT);
	RoomUserListControl(dwUserId, bEnterRoom ? true : false);
	if (bEnterRoom == 1) {
		ShowNotifyMessage(BRAC_GetUserName(dwUserId) + "&nbspenter room!", NOTIFY_TYPE_NORMAL);
		if (mTargetUserId == -1)						// Ĭ�ϴ�һ���û�������Ƶ
			RequestOtherUserVideo(dwUserId);
	}
	else {
		ShowNotifyMessage(BRAC_GetUserName(dwUserId) + "&nbspleave room!", NOTIFY_TYPE_NORMAL);
		if (dwUserId == mTargetUserId) {			// ��ǰ��������û��뿪���䣬Ĭ�����󷿼��������û�������Ƶ
			var bRequestOtherUser = false;
			var useridlist = BRAC_GetOnlineUser();
			for (var k = 0; k < useridlist.length; k++) {
				if (useridlist[k] == mSelfUserId)
					continue;
				RequestOtherUserVideo(useridlist[k]);
				bRequestOtherUser = true;
				break;
			}
			if (!bRequestOtherUser) {				// ���û�������û����ߣ������״̬
				mTargetUserId = -1;
				BRAC_SetVideoPos(0, GetID("AnyChatRemoteVideoDiv"), "ANYCHAT_VIDEO_REMOTE");
				//BRAC_SetVideoPos(0, GetID("AnyChatLocalVideoDiv"), "ANYCHAT_VIDEO_LOCAL");
			}
		}
	}
	DisplayScroll("room_div_userlist");
}

// ���������ѹرգ�����Ϣֻ���ڿͻ������ӷ������ɹ�֮�������쳣�ж�֮ʱ������reason��ʾ���ӶϿ���ԭ��
function OnAnyChatLinkClose(reason, errorcode) {
	AddLog("OnAnyChatLinkClose(reason=" + reason + ", errorcode=" + errorcode + ")", LOG_TYPE_EVENT);
	DisplayLoadingDiv(false);
	ShowRoomDiv(false);
	ShowHallDiv(false);
	ShowLoginDiv(true);
}

// �û�����Ƶ�豸״̬�仯��Ϣ��dwUserId��ʾ�û�ID�ţ�State��ʾ���û��Ƿ��Ѵ���Ƶ�ɼ��豸��0���رգ�1���򿪣�
function OnAnyChatMicStateChange(dwUserId, State) {

}

// �û�����ͷ״̬�����仯��dwUserId��ʾ�û�ID�ţ�State��ʾ����ͷ�ĵ�ǰ״̬��0��û������ͷ��1��������ͷ��û�д򿪣�2���򿪣�
function OnAnyChatCameraStateChange(dwUserId, State) {
	if (State == 0) GetID(dwUserId + "_CameraTag").src = "";
	if (State == 1) GetID(dwUserId + "_CameraTag").src = "../../assets/theme/img/advanceset/camera_false.png";
	if (State == 2) GetID(dwUserId + "_CameraTag").src = "../../assets/theme/img/advanceset/camera_true.png";
}

// �����û��������û���P2P��������״̬�����仯��dwUserId��ʾ�����û�ID�ţ�State��ʾ�����û��������û��ĵ�ǰP2P��������״̬��0��û�����ӣ�1����TCP���ӣ�2����UDP���ӣ�3��TCP��UDP���ӣ�
function OnAnyChatP2PConnectState(dwUserId, State) {

}

// �û�����˽������dwUserId��ʾ�����ߵ��û�ID�ţ�dwRequestId��ʾ˽�������ţ���ʶ������
function OnAnyChatPrivateRequest(dwUserId, dwRequestId) {
	console.log(dwUserId, dwRequestId);
}

// �û��ظ�˽������dwUserId��ʾ�ظ��ߵ��û�ID�ţ�errorcodeΪ��������
function OnAnyChatPrivateEcho(dwUserId, errorcode) {

}

// �û��˳�˽�ģ�dwUserId��ʾ�˳��ߵ��û�ID�ţ�errorcodeΪ��������
function OnAnyChatPrivateExit(dwUserId, errorcode) {

}

// ��Ƶͨ����Ϣ֪ͨ�ص�����
function OnAnyChatVideoCallEvent(dwEventType, dwUserId, dwErrorCode, dwFlags, dwParam, szUserStr) {
	AddLog("OnAnyChatVideoCallEvent(dwEventType=" + dwEventType + ", dwUserId=" + dwUserId + ", dwErrorCode=" + dwErrorCode + ", dwFlags=" + dwFlags + ", dwParam=" + dwParam + ", szUserStr=" + szUserStr + ")", LOG_TYPE_EVENT);

}

// �û���Ϣ����֪ͨ��dwUserId��ʾ�û�ID�ţ�dwType��ʾ�������
function OnAnyChatUserInfoUpdate(dwUserId, dwType) {
	AddLog("OnAnyChatUserInfoUpdate(dwUserId=" + dwUserId + ", dwType=" + dwType + ")", LOG_TYPE_EVENT);
}

// ��������״̬�仯��dwUserId��ʾ�����û�ID�ţ�dwStatus��ʾ�û��ĵ�ǰ�״̬��0 ���ߣ� 1 ����
function OnAnyChatFriendStatus(dwUserId, dwStatus) {
	AddLog("OnAnyChatFriendStatus(dwUserId=" + dwUserId + ", dwStatus=" + dwStatus + ")", LOG_TYPE_EVENT);

}


//ҵ������¼�֪ͨ
function OnAnyChatObjectEvent(dwObjectType, dwObjectId, dwEventType, dwParam1, dwParam2, dwParam3, dwParam4, strParam) {
	//AddLog("OnAnyChatObjectEvent(dwObjectType=" + dwObjectType + ", dwObjectId=" + dwObjectId +  ", dwEventType=" + dwEventType + ")", LOG_TYPE_EVENT);
	//refreshAgentServiceInfo();
	//console.log("ҵ������¼�֪ͨ��"+dwEventType);
	switch (dwEventType) {
		case ANYCHAT_OBJECT_EVENT_UPDATE: OnAnyChatObjectUpdate(dwObjectType, dwObjectId); break;
		case ANYCHAT_OBJECT_EVENT_SYNCDATAFINISH: OnAnyChatObjectSyncDataFinish(dwObjectType, dwObjectId); break;
		case ANYCHAT_AREA_EVENT_ENTERRESULT: OnAnyChatEnterAreaResult(dwObjectType, dwObjectId, dwParam1); break;
		case ANYCHAT_AREA_EVENT_LEAVERESULT: OnAnyChatLeaveAreaResult(dwObjectType, dwObjectId, dwParam1); break;
		case ANYCHAT_AREA_EVENT_STATUSCHANGE: OnAnyChatAreaStatusChange(dwObjectType, dwObjectId, dwParam1); break;
		case ANYCHAT_QUEUE_EVENT_STATUSCHANGE: OnAnyChatQueueStatusChanged(dwObjectType, dwObjectId); break;
		case ANYCHAT_QUEUE_EVENT_ENTERRESULT: OnAnyChatEnterQueueResult(dwObjectType, dwObjectId, dwParam1); break;
		case ANYCHAT_QUEUE_EVENT_LEAVERESULT: OnAnyChatLeaveQueueResult(dwObjectType, dwObjectId, dwParam1); break;
		case ANYCHAT_AGENT_EVENT_STATUSCHANGE: OnAnyChatAgentStatusChanged(dwObjectType, dwObjectId, dwParam1); break;
		case ANYCHAT_AGENT_EVENT_SERVICENOTIFY: OnAnyChatServiceStart(dwParam1, dwParam2, dwParam3, strParam); break;
		case ANYCHAT_AGENT_EVENT_WAITINGUSER: OnAnyChatAgentWaitingUser(); break;
		case ANYCHAT_QUEUE_EVENT_USERINFOLISTCHG: OnAnyChatAgentUserInfoListChg(dwObjectType, dwObjectId); break;
		case ANYCHAT_AGENT_EVENT_SERVICETIMEOUT: OnAnyChatServiceTimeout(dwObjectType, dwObjectId, dwEventType, dwParam1, dwParam2, dwParam3, dwParam4, strParam); break;
		default:
			break;
	}
}
function OnAnyChatServiceTimeout(dwObjectType, dwObjectId, dwEventType, dwParam1, dwParam2, dwParam3, dwParam4, strParam) {
	AddLog("OnAnyChatServiceTimeout(dwObjectType=" + dwObjectType + ", dwObjectId=" + dwObjectId + ", dwEventType=" + dwEventType + ")", LOG_TYPE_EVENT);
	AddLog('OnAnyChatServiceTimeout(' + dwParam1 + ',' + dwParam2 + ',' + dwParam3 + ',' + dwParam4 + ',' + strParam + ')', LOG_TYPE_EVENT);
	alert("ANYCHAT_AGENT_EVENT_SERVICETIMEOUT!");
}
//�����û���Ϣ���� dwObjectId��ʾ�û���Ϣ�и��µĶ���ID
function OnAnyChatAgentUserInfoListChg(dwObjectType, dwObjectId) {
	//console.log("��Ӫҵ������-"+dwObjectId+"�û���Ϣ�и��£�");
	var queueName = BRAC_ObjectGetStringValue(ANYCHAT_OBJECT_TYPE_QUEUE, dwObjectId, ANYCHAT_QUEUE_INFO_USERINFOLIST);
	console.log(dwObjectId + ":***������ص���ϢBRAC_ObjectGetStringValue��" + queueName + ";");
}

//ҵ��������ݸ����¼�
function OnAnyChatObjectUpdate(dwObjectType, dwObjectId) {
	var str = null;
	//AddLog('OnAnyChatObjectUpdate(' + dwObjectType + ',' + dwObjectId + ')', LOG_TYPE_EVENT);

	if (dwObjectType == ANYCHAT_OBJECT_TYPE_AREA) {
		areaIdArray[areaArrayIdx] = dwObjectId;
		areaArrayIdx++;
	} else if (dwObjectType == ANYCHAT_OBJECT_TYPE_QUEUE) {

	} else if (dwObjectType == ANYCHAT_OBJECT_TYPE_AGENT) {

	}
}

//ҵ�����ͬ������¼�
function OnAnyChatObjectSyncDataFinish(dwObjectType, dwObjectId) {
	AddLog('OnAnyChatObjectSyncDataFinish(' + dwObjectType + ',' + dwObjectId + ')', LOG_TYPE_EVENT);

	if (dwObjectType == ANYCHAT_OBJECT_TYPE_AREA) {
		mCurrentStatus = CLIENT_STATUS_AREA;
		showSerivceArea();
	}
}

// �����������֪ͨ�¼�
function OnAnyChatEnterAreaResult(dwObjectType, dwObjectId, dwErrorCode) {
	AddLog('OnAnyChatEnterAreaResult(' + dwObjectType + ',' + dwObjectId + ',' + dwErrorCode + ')', LOG_TYPE_EVENT);
	if (dwErrorCode == 0) {
		colorIdx = 0;
		// �����������ɹ�
		if (userType == USER_TYPE_CLIENT) {//�ͻ�
			mCurrentStatus = CLIENT_STATUS_QUEUE;

			//��ȡ����
			var queueList = BRAC_ObjectGetIdList(ANYCHAT_OBJECT_TYPE_QUEUE);
			if (queueList.length == 0) {
				$("#LOADING_GREY_DIV").hide(); //�����ɲ�
				ForSession("Ӫҵ����û�п��õĶ���...", true);
				//�뿪��Ӫҵ��
				leaveFlag = BRAC_ObjectControl(ANYCHAT_OBJECT_TYPE_AREA, dwObjectId, ANYCHAT_AREA_CTRL_USERLEAVE, dwErrorCode, 0, 0, 0, "");
				return;
			}
			for (var i in queueList) {
				var queueListId = parseInt(queueList[i]);
				/**��ȡ��������*/
				var queueName = BRAC_ObjectGetStringValue(ANYCHAT_OBJECT_TYPE_QUEUE, queueListId, ANYCHAT_OBJECT_INFO_NAME);
				/**��ȡ�����Ŷ�����*/
				var queueLength = BRAC_ObjectGetIntValue(ANYCHAT_OBJECT_TYPE_QUEUE, queueListId, ANYCHAT_QUEUE_INFO_LENGTH);
				queueLength = queueLength < 0 ? 0 : queueLength;
				/**��ȡ������Ϣ*/
				var queueInfo = BRAC_ObjectGetStringValue(ANYCHAT_OBJECT_TYPE_QUEUE, queueListId, ANYCHAT_OBJECT_INFO_DESCRIPTION);
				var attributeValue = BRAC_ObjectGetIntValue(ANYCHAT_OBJECT_TYPE_QUEUE, queueListId, ANYCHAT_OBJECT_INFO_ATTRIBUTE);

				var queueSkillName = "";
				//��ȡ�����������ܷ���
				var skillList = getFlagList(attributeValue);
				for (var skillValue in skillList) {
					var arrayId = getZhiShu(skillValue);
					if (arrayId >= skillsArray.length) {
						arrayId = 0;
					}
					if (queueSkillName == "") {
						queueSkillName = skillsArray[arrayId];
					} else {
						queueSkillName = queueSkillName + "," + skillsArray[arrayId];
					}
				}

				$("#LOADING_GREY_DIV").hide(); //�����ɲ�
				$('#poptip li[areaId]').hide(); //���ط�����
				$("#enterRoom h2").text(queueListName);
				var liObject = $('<li class="queue-item" queueid="' + queueListId + '">' +
					'<span class="queue-item-layout">' +
					'<span class="queue-item-layout-title">' + queueName + '</span>' +
					'<span class="queue-item-layout-desc">' + queueInfo + '</span>' +
					'<span class="queue-item-layout-desc">' + '�������飺' + queueSkillName + '</span>' +
					'<span class="queue-item-layout-desc">' + '��ǰ�Ŷ�������<strong>' + queueLength + " ��" + '</strong></span>' +
					'</span>' +
					'<a class="queue-item-link"><img class="queue-item-pic" src="./img/queue.png" /></a>' +
					'<span class="queue-item-layout-btn">' + '<a class="btn btn-info">��������</a>' + '</span>' +
					'</li>');
				//liObject.css("background-color", colorQueueArray[colorIdx]);
				$("#poptip").append(liObject);
				colorIdx++;
				if (colorIdx == 3) {
					colorIdx = 0;
				}
			}
		}

		//��ϯ

		if (userType == USER_TYPE_AGENT) {

			$("#LOADING_GREY_DIV").hide(); //���صȴ��ɲ�
			mCurrentStatus = AGENT_STATUS_SERVICE;
			console.log("-------------�����������֪ͨ--------------");
			refreshAgentServiceInfo();
			var queueList = BRAC_ObjectGetIdList(ANYCHAT_OBJECT_TYPE_QUEUE);
			//AddLog("��������BRAC_ObjectGetIdList(" + queueList + ")",LOG_TYPE_EVENT);//��ӡ������Ϣ
			//console.log("��������BRAC_ObjectGetIdList:" + queueList.length + ";");//��ӡ������Ϣ
			//console.log("��������BRAC_ObjectGetIdList:" + queueList + ";");
			//��ϯ����Ӫҵ���ĳ�ʼ״̬Ϊ"�ر�"
			var errorcode = BRAC_ObjectControl(ANYCHAT_OBJECT_TYPE_AGENT, mSelfUserId, ANYCHAT_AGENT_CTRL_SERVICESTATUS, ANYCHAT_AGENT_STATUS_CLOSEED, 0, 0, 0, "");
			AddLog("BRAC_ObjectControl(" + ANYCHAT_OBJECT_TYPE_AGENT + "," + mSelfUserId + "," + ANYCHAT_AGENT_CTRL_SERVICESTATUS + "," + ANYCHAT_AGENT_STATUS_CLOSEED + ",0,0,0,''" + ")=" + errorcode, LOG_TYPE_API);

			//	        setInterval(
			//					function() {
			//						refreshAgentServiceInfo();
			//			}, 5000);			
		}
	}
}

// �뿪��������֪ͨ�¼�
function OnAnyChatLeaveAreaResult(dwObjectType, dwObjectId, dwErrorCode) {
	AddLog('OnAnyChatLeaveAreaResult(' + dwObjectType + ',' + dwObjectId + ',' + dwErrorCode + ')', LOG_TYPE_EVENT);
	if (userType == USER_TYPE_CLIENT) {
		mCurrentStatus = CLIENT_STATUS_AREA;
	}
	if (userType == USER_TYPE_AGENT) {
		mCurrentStatus = AGENT_STATUS_AREA;
		//�ر���ϯ�˵ı�����Ƶ
		//startVideo(mSelfUserId, GetID("localVideoPos"), "ANYCHAT_VIDEO_LOCAL",0);	
		BRAC_UserCameraControl(mSelfUserId, 0);
	}

}

//Ӫҵ��״̬�仯
function OnAnyChatAreaStatusChange(dwObjectType, dwObjectId, dwErrorCode) {
	AddLog('OnAnyChatAreaStatusChange(' + dwObjectType + ',' + dwObjectId + ',' + dwErrorCode + ')', LOG_TYPE_EVENT);

	if (userType == USER_TYPE_AGENT) {
		console.log("-----------Ӫҵ��״̬�仯------------------");
		refreshAgentServiceInfo();
	}
}

// ����״̬�仯
function OnAnyChatQueueStatusChanged(dwObjectType, dwObjectId) {
	AddLog('OnAnyChatQueueStatusChanged(' + dwObjectType + ',' + dwObjectId + ')', LOG_TYPE_EVENT);
	console.log('OnAnyChatQueueStatusChanged(' + dwObjectType + ',' + dwObjectId + ')');
	if (userType == USER_TYPE_AGENT) {
		console.log("--------------����״̬�仯-----------------");
		refreshAgentServiceInfo();
		refreshQueueInfoDisplay(dwObjectId);
	}

	if (queueid == dwObjectId) {
		refreshUserWaitingInfo(dwObjectId);
	}

	//refreshUserWaitingInfo(dwObjectId);
	//refreshQueueInfoDisplay(dwObjectId);//2022
}

// �����û�������н��
function OnAnyChatEnterQueueResult(dwObjectType, dwObjectId, dwErrorCode) {
	AddLog('OnAnyChatEnterQueueResult(' + dwObjectType + ',' + dwObjectId + ',' + dwErrorCode + ')', LOG_TYPE_EVENT);
	currentSelectedQueueName = BRAC_ObjectGetStringValue(ANYCHAT_OBJECT_TYPE_QUEUE, dwObjectId, ANYCHAT_OBJECT_INFO_NAME);
	$("#enterRoom h2").text(currentSelectedQueueName + " - ���񴰿�");
	isShowReturnBtn(false);

	$("#LOADING_GREY_DIV").hide();//���صȴ��ɲ�
	$("#poptip").hide(); //���ض���
	$("#queueMsg1").show(); //������ʾ�Ŷ���Ϣ
	$("#queueMsg2").hide(); //���غ�����Ϣ
	$(".callBox").show(); //��ʾ������Ϣ����
	$("#queueMsg1 strong:eq(2)").text(0); //�����Ŷ�ʱ��
	clearInterval(waitTimeSet);
	waitTimeSet = setInterval(function () {
		var time = formatSeconds(BRAC_ObjectGetIntValue(ANYCHAT_OBJECT_TYPE_QUEUE, queueid, ANYCHAT_QUEUE_INFO_WAITTIMESECOND));
		$("#queueMsg1 strong:eq(2)").text(time);
	}, 1000);

	if (userType == USER_TYPE_CLIENT) {
		mCurrentStatus = CLIENT_STATUS_QUEUEING;
	}
}

// �����û��뿪���н��
function OnAnyChatLeaveQueueResult(dwObjectType, dwObjectId, dwErrorCode) {
	AddLog('OnAnyChatLeaveQueueResult(' + dwObjectType + ',' + dwObjectId + ',' + dwErrorCode + ')', LOG_TYPE_EVENT);
	if (dwErrorCode == 0) isShowReturnBtn(true);
	currentSelectedQueueName = "";

	if ($(".callBox").css("display") != "block") {
		$("#LOADING_GREY_DIV").hide();//���صȴ��ɲ�
		$("#poptip").show();
		$("#poptip li[queueid]").show(); //��ʾ�����б�
	}

	if (userType == USER_TYPE_CLIENT) {
		mCurrentStatus = CLIENT_STATUS_QUEUE;
	}
}

// ��ϯ״̬�仯
function OnAnyChatAgentStatusChanged(dwObjectType, dwObjectId, dwParam1) {
	AddLog('OnAnyChatAgentStatusChanged(' + dwObjectType + ',' + dwObjectId + ',' + dwParam1 + ')', LOG_TYPE_EVENT);
	if (dwObjectType == ANYCHAT_OBJECT_TYPE_AGENT && currentAgentID == dwObjectId) {
		if (dwParam1 == ANYCHAT_AGENT_STATUS_WAITTING) {
			console.log("------------��ϯ״̬�仯--------------");
			refreshAgentServiceInfo();

			startServiceTag = false;
			$("#LOADING_GREY_DIV span").show();
			refreshServicedUserInfo(-1);

			isShowReturnBtn(true);

			$("#serviceInfoTable tr:eq(3) td:eq(1)").text("׼��");
			$("#startService").attr("disabled", false);
			$("#agentLeave").attr("disabled", false);
			$("#stopService").attr("disabled", true);
			$("#remoteControlBtn").attr("disabled", true);
			$("#shareDesktopBtn").attr("disabled", true);
			$("#snapshotBtn").attr("disabled", true);
			$("#recordBtn").attr("disabled", true);

			$("#serviceInfoTable tr:eq(5) td:eq(0)").text("");

		} else if (dwParam1 == ANYCHAT_AGENT_STATUS_WORKING) {
			startServiceTag = true;
			$("#serviceInfoTable tr:eq(3) td:eq(1)").text("æµ");
			refreshServicedUserInfo(mTargetUserId);
			$("#startService").attr("disabled", true);
			$("#agentLeave").attr("disabled", true);
			$("#stopService").attr("disabled", false);
			$("#remoteControlBtn").attr("disabled", true);
			$("#shareDesktopBtn").attr("disabled", false);
			$("#snapshotBtn").attr("disabled", false);
			$("#recordBtn").attr("disabled", false);
		} else if (dwParam1 == ANYCHAT_AGENT_STATUS_PAUSED) {
			startServiceTag = false;
			$("#serviceInfoTable tr:eq(3) td:eq(1)").text("�뿪");
			$("#startService").attr("disabled", false);
			$("#agentLeave").attr("disabled", false);
			$("#stopService").attr("disabled", true);
			$("#remoteControlBtn").attr("disabled", true);
			$("#shareDesktopBtn").attr("disabled", true);
			$("#snapshotBtn").attr("disabled", true);
			$("#recordBtn").attr("disabled", true);
		} else if (dwParam1 == ANYCHAT_AGENT_STATUS_CLOSEED) {
			startServiceTag = false;
			$("#serviceInfoTable tr:eq(3) td:eq(1)").text("δ����");
			$("#startService").attr("disabled", false);
			$("#agentLeave").attr("disabled", false);
			$("#stopService").attr("disabled", true);
			$("#remoteControlBtn").attr("disabled", true);
			$("#shareDesktopBtn").attr("disabled", true);
			$("#snapshotBtn").attr("disabled", true);
			$("#recordBtn").attr("disabled", true);
		}

	}
}

// ��ϯ����ʼ
function OnAnyChatServiceStart(dwAgentId, clientId, dwQueueId, strParam) {
	AddLog('OnAnyChatServiceStart(' + dwAgentId + ',' + clientId + ',' + dwQueueId + ')', LOG_TYPE_EVENT);
	console.log('OnAnyChatServiceStart(' + dwAgentId + ',' + clientId + ',' + dwQueueId + ',' + strParam + ')');
	if (userType == USER_TYPE_AGENT && mSelfUserId == dwAgentId) {
		mTargetUserId = clientId;//�ͻ�id		    	
		$("#LOADING_GREY_DIV span").hide();
		userflags = BRAC_ObjectGetIntValue(ANYCHAT_OBJECT_TYPE_CLIENTUSER, mTargetUserId, ANYCHAT_OBJECT_INFO_FLAGS);
		if ((userflags & 16384) != 0) {

			stringtag = BRAC_ObjectGetStringValue(ANYCHAT_OBJECT_TYPE_CLIENTUSER, mTargetUserId, ANYCHAT_OBJECT_INFO_STRINGTAG);
			console.log("�û���·����tradeNo��" + stringtag + "��");
			//var start_error = BRAC_ObjectControl(ANYCHAT_OBJECT_TYPE_AGENT, mSelfUserId,ANYCHAT_AGENT_CTRL_STARTSERVICE,mTargetUserId);//������ʼ����//var ANYCHAT_AGENT_CTRL_STARTSERVICE=603;	// ��ǰ����Ŀ�ʼʱ�䣬����
			//AddLog("BRAC_ObjectControl(" + ANYCHAT_OBJECT_TYPE_AGENT+","+mSelfUserId+","+ANYCHAT_AGENT_CTRL_STARTSERVICE + "," + mTargetUserId + ")=" + start_error, LOG_TYPE_API);


			var r = confirm("�û���·����tradeNo��" + stringtag + "��Userid:" + mTargetUserId + ";");
			if (r == true) {
				console.log("�㰴����\"ȷ��\"��ť!");
				var start_error = BRAC_ObjectControl(ANYCHAT_OBJECT_TYPE_AGENT, mSelfUserId, ANYCHAT_AGENT_CTRL_STARTSERVICE, mTargetUserId);//������ʼ����//var ANYCHAT_AGENT_CTRL_STARTSERVICE=603;	// ��ǰ����Ŀ�ʼʱ�䣬����
				console.log("BRAC_ObjectControl(" + ANYCHAT_OBJECT_TYPE_AGENT + "," + mSelfUserId + "," + ANYCHAT_AGENT_CTRL_STARTSERVICE + "," + mTargetUserId + ")=" + start_error);
				//BRAC_ObjectControl(ANYCHAT_OBJECT_TYPE_AGENT, mSelfUserId, ANYCHAT_AGENT_CTRL_FINISHSERVICE,mTargetUserId);
			} else {
				console.log("�㰴����\"ȡ��\"��ť!");
				var reject_error = BRAC_ObjectControl(ANYCHAT_OBJECT_TYPE_AGENT, mSelfUserId, ANYCHAT_AGENT_CTRL_FINISHSERVICE, 100104);//�������ܾ�
				AddLog("BRAC_ObjectControl(" + ANYCHAT_OBJECT_TYPE_AGENT + "," + mSelfUserId + "," + ANYCHAT_AGENT_CTRL_STARTSERVICE + ",100104," + mTargetUserId + ")=" + reject_error, LOG_TYPE_API);
			}

			//var start_error = BRAC_ObjectControl(ANYCHAT_OBJECT_TYPE_AGENT, mSelfUserId,ANYCHAT_AGENT_CTRL_STARTSERVICE,mTargetUserId);//������ʼ����
			//var ANYCHAT_AGENT_CTRL_STARTSERVICE=603;	// ��ǰ����Ŀ�ʼʱ�䣬����
			//AddLog("BRAC_ObjectControl(" + ANYCHAT_OBJECT_TYPE_AGENT+","+mSelfUserId+","+ANYCHAT_AGENT_CTRL_STARTSERVICE + "," + mTargetUserId + ")=" + start_error, LOG_TYPE_API);

		} else {
			if (isAutoMode == 0) {
				VideoCallRequest(clientId);//�����û�
			} else {
				//����͸��ͨ������
				var jsonStr = "{\"commandType\":\"videoCall\",\"targetUserId\":" + dwAgentId + ",\"isAutoMode\":1}";
				BRAC_TransBuffer(clientId, jsonStr);
			}
		}
	}
	if (userType == USER_TYPE_CLIENT && mSelfUserId == clientId) {
		mTargetUserId = dwAgentId;
	}
	$("#remoteControlBtn").attr("disabled", false);
}

//������û�пͻ�����ϯ�˴�����ʽ
function OnAnyChatAgentWaitingUser() {
	AddLog('OnAnyChatAgentWaitingUser()', LOG_TYPE_EVENT);
	if ($("#remoteVideoPos").html() == "") {
		$('#LOADING_GREY_DIV').hide();
		startServiceTag = false;
		$("#LOADING_GREY_DIV span").show();
		ForSession('��ǰ��������û�пͻ���', true);
	}
}

function settingClientUserInfo(mUserSettingMode) {
	//ѡ��"������������"ʱ���ȴӺ�̨ȷ���û�����
	if (mUserSettingMode == 2) {
		var Flags = BRAC_ObjectGetIntValue(ANYCHAT_OBJECT_TYPE_CLIENTUSER, mSelfUserId, ANYCHAT_OBJECT_INFO_FLAGS);

		if (Flags == 0) userType = USER_TYPE_CLIENT;

		if (Flags == 2) { userType = USER_TYPE_AGENT; isAutoMode = 0; }
		if (Flags == 18) { userType = USER_TYPE_AGENT; isAutoMode = 1; }
	}

	dwPriority = parseInt($("#dwPrioritySelect option:selected").val());

	switch (userType) {
		case USER_TYPE_CLIENT:
			dwAgentFlags = 0; //�ͻ���ʶ

			mCurrentStatus = CLIENT_STATUS_AREA;

			//�����û�������Ϣ����
			InitClientObjectInfo(mSelfUserId, dwAgentFlags, dwPriority, dwAttribute);

			break;

		case USER_TYPE_AGENT:
			currentAgentID = mSelfUserId;

			if (mUserSettingMode == 1) {
				isAutoMode = parseInt($("#routeModeSelect option:selected").val());
				if (isAutoMode == 1) {
					dwAgentFlags = 0x1202; //��ϯ��ʶANYCHAT_OBJECT_FLAGS_AGENT + ANYCHAT_OBJECT_FLAGS_AUTOMODE + ANYCHAT_OBJECT_FLAGS_ONLYSYNCNEED +0x40

				} else {
					dwAgentFlags = 0x1202; //��ϯ��ʶANYCHAT_OBJECT_FLAGS_AGENTE + ANYCHAT_OBJECT_FLAGS_ONLYSYNCNEED + 0x40
				}

				if (routeType == 1) {
					//�������ʼֵ
					dwAttribute = "";
					var queueGroupValue = "";
					$("input[name='queueCheckBoxGroup']").each(function () {
						if (true == $(this)[0].checked) {
							if (queueGroupValue == "") {
								queueGroupValue = parseInt($(this).attr('value'));
							} else {
								queueGroupValue = queueGroupValue + "," + parseInt($(this).attr('value'));
							}
						}
					});
					queueGroupValue = "[" + queueGroupValue + "]";

					dwAttribute = "{\"flags\":" + dwAgentFlags + ",\"priority\":" + dwPriority + ",\"queuegroups\":" + queueGroupValue + "}";
				}
				else if (routeType == 2) {
					//�������ʼֵ
					dwAttribute = "";
					var skillGroupValue = "";
					$("input[name='skillCheckBoxGroup']").each(function () {
						if (true == $(this)[0].checked) {
							if (skillGroupValue == "") {
								skillGroupValue = parseInt($(this).attr('value'));
							} else {
								skillGroupValue = skillGroupValue + "," + parseInt($(this).attr('value'));
							}
						}
					});
					skillGroupValue = "[" + skillGroupValue + "]";

					dwAttribute = "{\"flags\":" + dwAgentFlags + ",\"priority\":" + dwPriority + ",\"skillgroups\":" + skillGroupValue + "}";
				}

				//������ϯ������Ϣ����
				InitClientObjectInfo(mSelfUserId, dwAgentFlags, dwPriority, dwAttribute);
			}

			mCurrentStatus = AGENT_STATUS_AREA;
			servantName = $("#username").val(); //�ͷ������˻���

			initAgentVideoForm();

		default:
			break;
	}

}

// �յ�¼�����������¼�
function OnAnyChatRecordSnapShot(dwUserId, lpFileName, dwParam, bRecordType) {
	AddLog('OnAnyChatRecordSnapShot(' + dwUserId + ',' + lpFileName + ',' + dwParam + ',' + bRecordType + ')', LOG_TYPE_EVENT);
}





